package com.lzh.interceptor;

import com.lzh.auto.TokenInterceptorProperties;
import com.lzh.token.TokenTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


public class TokenWebConfig implements WebMvcConfigurer {

    @Autowired
    TokenTemplate tokenTemplate;

    TokenInterceptorProperties tokenInterceptorProperties;

    public TokenWebConfig(TokenInterceptorProperties tokenInterceptorProperties,TokenTemplate tokenTemplate){
        this.tokenInterceptorProperties = tokenInterceptorProperties;
        this.tokenTemplate=tokenTemplate;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TokenInterceptor(tokenTemplate))
                .addPathPatterns(tokenInterceptorProperties.getPathPatterns())
                .excludePathPatterns(tokenInterceptorProperties.getExcludePathPatterns());
    }
}
